package xinxin.com.IteratorPatternBasic.Iterator;

import xinxin.com.IteratorPatternBasic.Aggregate.ConcreteAggregate;

/**
 * @author ：史鑫鑫
 * @date ：Created in 2019/3/29 9:36
 * @describe ：正向迭代器
 */
public class ConcreteIterator extends Iterator {
    private ConcreteAggregate aggregate;
    private int current;

    public ConcreteIterator(ConcreteAggregate aggregate) {
        this.aggregate = aggregate;
        this.current = 0;
    }

    @Override
    public Object First() {
        return aggregate.get(0);
    }

    @Override
    public Object Next() {
        Object object = null;
        current++;
        if (current < aggregate.getCount()) {
            object = aggregate.get(current);
        }
        return object;
    }

    @Override
    public boolean IsDone() {
        return current >= aggregate.getCount() ? true : false;
    }

    @Override
    public Object CurrentItem() {
        return aggregate.get(current);
    }
}
